import React, { useEffect, useState } from 'react';

// 演示 在函数式 组件中使用 state
export default function Example() {
    const [count, setCount] = useState(0);

    // 相当于 componentDidMount 和 componentDidUpdate:
    useEffect(() => {
        document.title = `You clicked ${count} times.`
    }, [count]) // 仅在 count 更改时更新

    return (
        <div>
            <p>You clicked {count} times.</p>
            <button onClick={() => setCount(count + 1)}>
                Click me
            </button>
        </div>
    )
}
